﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
using MYTech.Data.Oracle;
using MYTech.IO;
using MYTech.Oracle;
using MYTech.Utils;

namespace MYTech.Data.Oracle
{
    public class LoadConfig
    {
        public static Connect Connection;
        private static string filePath = Application.StartupPath + "\\settings.xml";
        public static void LoadOracleConfig()
        {
            if (File.Exists(filePath))
            {
                string info = FileHelper.TxtReader(filePath);
                Connection = SerialiazeHelper.XmlDeserialize<Connect>(info);
                DataHelper.SetConnection(Connection);
            }
        }

        public static void SetOracleConfig(string ip, string db, int port, string username, string password)
        {
            Connection = new Connect(ip, port, db, username, password);
            DataHelper.SetConnection(Connection);
        }

        public static bool SaveOracleConfig()
        {
            if (Connection != null)
            {
                string info = SerialiazeHelper.XmlSerialiaze(Connection);
                FileHelper.WriteToTxt(filePath, info, true);
                return true;
            }
            return false;
        }
    }
}
